#include "Vector2.h"

Vector2::Vector2() : m_x(0), m_y(0)
{
}
Vector2::Vector2(double p_x, double p_y) : m_x(p_x), m_y(p_y)
{
}


double Vector2::getLength() const
{
	return (double)sqrt(m_x*m_x + m_y*m_y);
}
double Vector2::getX() const
{
	return m_x;
}
double Vector2::getY() const
{
	return m_y;
}


void Vector2::setX(double p_x)
{
	m_x = p_x;
}
void Vector2::setY(double p_y)
{
	m_y = p_y;
}


void Vector2::invert()
{
	m_x = -m_x;
	m_y = -m_y;
}
void Vector2::normalize(){
	double length = getLength();
	m_x /= length;
	m_y /= length;
}
double Vector2::dotProduct(const Vector2 &p_vector) const
{
	return m_x*p_vector.m_x + m_y*p_vector.m_y;
}

Vector2& Vector2::operator=(const Vector2 &p_vector)
{
	if(this != &p_vector)
	{
		m_x = p_vector.m_x;
		m_y = p_vector.m_y;
	}
	return *this;
}
const Vector2 Vector2::operator+(const Vector2 &p_vector) const
{
	Vector2 result = *this;
	result += p_vector;
	return result;
}
Vector2& Vector2::operator+=(const Vector2 &p_vector)
{
	m_x += p_vector.m_x;
	m_y += p_vector.m_y;
	return *this;
}
const Vector2 Vector2::operator-(const Vector2 &p_vector) const
{
	Vector2 result = *this;
	result -= p_vector;
	return result;
}
Vector2& Vector2::operator-=(const Vector2 &p_vector)
{
	m_x -= p_vector.m_x;
	m_y -= p_vector.m_y;
	return *this;
}
const Vector2 Vector2::operator*(double p_scalar) const
{
	Vector2 result = *this;
	result *= p_scalar;
	return result;
}
Vector2& Vector2::operator*=(double p_scalar)
{
	m_x *= p_scalar;
	m_y *= p_scalar;
	return *this;
}
const Vector2 Vector2::operator/(double p_scalar) const
{
	Vector2 result = *this;
	result /= p_scalar;
	return result;
}
Vector2& Vector2::operator/=(double p_scalar)
{
	m_x /= p_scalar;
	m_y /= p_scalar;
	return *this;
}
bool Vector2::operator==(const Vector2 &p_vector) const
{
	return m_x == p_vector.m_x &&
	m_y == p_vector.m_y;
}
